home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / posix / fcntl / open.txh < prev   
Encoding:
Text File  |  1995-07-10  |  1.8 KB  |  88 lines

  1. @node open, io
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <fcntl.h>
  6. #include <sys/stat.h> /* for mode definitions */
  7.  
  8. int open(const char *file, int mode /*, int permissions */);
  9. @end example
  10.  
  11. @subheading Description
  12.  
  13. This function opens the named @var{file} in the given @var{mode}, which
  14. is any combination of the following:
  15.  
  16. @table @code
  17.  
  18. @item O_RDONLY
  19.  
  20. The file is opened for reading.
  21.  
  22. @item O_WRONLY
  23.  
  24. The file is opened for writing.
  25.  
  26. @item O_RDWR
  27.  
  28. The file is opened for both reading and writing.
  29.  
  30. @item O_CREAT
  31.  
  32. If the file does not exist, it is created. @xref{creat}.
  33.  
  34. @item O_TRUNC
  35.  
  36. If the file does exist, it is truncated to zero bytes.
  37.  
  38. @item O_EXCL
  39.  
  40. If the file exists, and @code{O_CREAT} is also specified, the
  41. @code{open} call will fail. 
  42.  
  43. @item O_APPEND
  44.  
  45. The file pointer is positioned at the end of the file before each write. 
  46.  
  47. @item O_TEXT
  48.  
  49. The file is opened in text mode, meaning that Ctrl-M characters are
  50. stripped on reading and added on writing as needed.  The default mode is
  51. specified by the @code{_fmode} variable @ref{_fmode}. 
  52.  
  53. @item O_BINARY
  54.  
  55. The file is opened in binary mode.
  56.  
  57. @end table
  58.  
  59. If the file is created by this call, it will be given the read/write
  60. permissions specified by @var{permissions}, which may be any combination
  61. of these values:
  62.  
  63. @table @code
  64.  
  65. @item S_IRUSR
  66.  
  67. The file is readable.  This is always true for MS-DOS
  68.  
  69. @item S_IWUSR
  70.  
  71. The file is writable.
  72.  
  73. @end table
  74.  
  75. Other @code{S_I*} values may be included, but they will be ignored.
  76.  
  77. @subheading Return Value
  78.  
  79. If successful, the file descriptor is returned.  On error, a negative
  80. number is returned and @code{errno} is set to indicate the error. 
  81.  
  82. @subheading Example
  83.  
  84. @example
  85. int q = open("/tmp/foo.dat", O_RDONLY|O_BINARY);
  86. @end example
  87.  
  88.